package client;

import entity.Customer;

import java.util.Date;

import entity.CasualSubscription;
import entity.DisabledPlace;
import entity.FullSubscription;
import entity.OneTimeCostumerOrder;
import entity.Order;
import entity.ParkingLot;
import entity.ParkingLotWorker;
import entity.Prices;
import entity.Subscription;

public class Client {
	public Client(){};
	public static void saveSubscriptionToDB(Object sub)	//save new subscription (should check if its full or not)
	{
		System.out.println("saving subscription:\n\n"+((Subscription)sub).toString());
	}
	public static void UpdateParkingLotToDB(Object pl)	//update change in a parking lot
	{
		System.out.println("updating parking lot: "+((ParkingLot)pl).getParking_lot_name());
	}
	public static String getLoggedIn()	//in the system main
	{
		return "203247267";
	}
	public static int getParkingLot()	//in the information station main
	{
		return 1;
	}
	
	public static String getParkingLotNameByNumber(int pNum)	//can use "getParkingLots_sorted()"
	{
		ParkingLot[] plots=getParkingLots_sorted();
		for (int i=0; i<plots.length;i++)
			if (plots[i].getParking_lot_number()==pNum)
				return plots[i].getParking_lot_name();
		return null;
	}
	
	public static ParkingLot[] getParkingLots_sorted()	//parking lots are sorted by parking lot number(parking lot i is at [i-1])
	{
		ParkingLot[] plots=new ParkingLot[6];
		plots[0]=new ParkingLot();
		plots[0].setParking_lot_number(0);
		plots[0].setParking_lot_name("ramatgan");
		plots[0].createParkingLot(3, 3, 4);
		
		plots[1]=new ParkingLot();
		plots[1].setParking_lot_number(1);
		plots[1].setParking_lot_name("givataim");
		plots[1].createParkingLot(3, 3, 4);
		plots[2]=new ParkingLot();
		plots[2].setParking_lot_number(2);
		plots[2].setParking_lot_name("telaviv");
		plots[2].createParkingLot(3, 3, 4);
		plots[3]=new ParkingLot();
		plots[3].setParking_lot_number(3);
		plots[3].setParking_lot_name("natania");
		plots[3].createParkingLot(3, 3, 4);
		plots[4]=new ParkingLot();
		plots[4].setParking_lot_number(4);
		plots[4].setParking_lot_name("haifa");
		plots[4].createParkingLot(3, 3, 4);
		plots[5]=new ParkingLot();
		plots[5].setParking_lot_number(5);
		plots[5].setParking_lot_name("beersheva");
		plots[5].createParkingLot(3, 3, 4);
		
		Date d=new Date();
		plots[0].insertCar("1111111", d);
		plots[0].insertCar("2222222", d);
		plots[0].insertCar("3333333", d);
		plots[0].insertCar("4444444", d);
		plots[0].insertCar("5555555", d);
		plots[0].insertCar("6666666", d);
		plots[0].insertCar("7777777", d);
		plots[0].insertCar("8888888", d);
		plots[0].insertCar("9999999", d);
		plots[0].insertCar("1234568", d);
		plots[0].insertCar("1234569", d);
		plots[0].insertCar("1234560", d);
		return plots;
	}
	
	public static FullSubscription  getFullSubscriptionByNumber(int subscription_number) //can use "getFullSubscriptions()"
	{
		FullSubscription sub=new FullSubscription();
		Date startDate=new Date();
		Date endDate=new Date();
		startDate.setTime(startDate.getTime()-1000*60*60*24*14);
		endDate.setTime(endDate.getTime()+1000*60*60*24*14);
		sub.setCar_number("1234567");
		sub.setCustomer_id("203247267");
		sub.setEnd_date(endDate);
		sub.setStart_date(startDate);
		if(subscription_number==1)
			return sub;
		return null;
	}
	
	
	public static CasualSubscription  getCasualSubscriptionByNumber(int subscription_number) //can use "getCasualSubscriptions()"
	{
		CasualSubscription sub=new CasualSubscription();
		Date startDate=new Date();
		Date endDate=new Date();
		startDate.setTime(startDate.getTime()-1000*60*60*24*14);
		endDate.setTime(endDate.getTime()+1000*60*60*24*14);
		sub.setCar_number("1234567");
		sub.setCustomer_id("203247267");
		sub.setEnd_date(endDate);
		sub.setStart_date(startDate);
		sub.setParking_lot_number(1);
		sub.setleaving_time(0, 0, 0);
		if(subscription_number==2)
			return sub;
		return null;
	}
	
	public static Order [] getOrders()
	{
		Order [] subs=new Order[3];
		Date [] dates=new Date[3];
		dates[0]=new Date();
		dates[0].setTime(dates[0].getTime()-1000*60);
		dates[1]=new Date();
		dates[1].setTime(dates[0].getTime()+1000*60*60*48);
		dates[2]=new Date();
		dates[2].setTime(dates[0].getTime()-1000*60*60*72);
		Date [] dates2=new Date[3];
		dates2[0]=new Date();
		dates2[0].setTime(dates[0].getTime()+1000*60*60*4);
		dates2[1]=new Date();
		dates2[1].setTime(dates[0].getTime()+1000*60*60*51);
		dates2[2]=new Date();
		dates2[2].setTime(dates[0].getTime()+1000*60*60*75);
		subs[0]=new Order("203247267","7777777",1,dates[0],dates2[0],"Or_marm@walla.com");
		subs[1]=new Order("123123123","8888888",1,dates[1],dates2[1],"Or_marm@walla.com");
		subs[2]=new Order("321321321","9999999",2,dates[2],dates2[2],"Or_marm@walla.com");
		
		return subs;
	}
	
	public static FullSubscription [] getFullSubscriptionById(String loggedIn) ////can use "getFullSubscriptions()"
	{
		FullSubscription [] subs=new FullSubscription[3];
		Date [] dates=new Date[3];
		
		subs[0]=new FullSubscription();
		subs[0].setCustomer_id("203247267");
		subs[0].setCar_number("4444444");
		dates[0]=new Date();
		dates[0].setTime(dates[0].getTime()-1000*60*60*24);
		subs[0].setStart_date(dates[0]);
		dates[0]=(Date) dates[0].clone();
		dates[0].setTime(dates[0].getTime()+1000*60*60*48);
		subs[0].setEnd_date(dates[0]);
		subs[1]=new FullSubscription();
		subs[1].setCustomer_id("203247267");
		subs[1].setCar_number("5555555");
		dates[1]=new Date();
		dates[1].setTime(dates[1].getTime()-1000*60*60*48);
		subs[1].setStart_date(dates[1]);
		dates[1]=(Date) dates[1].clone();
		dates[1].setTime(dates[1].getTime()+1000*60*60*72);
		subs[1].setEnd_date(dates[1]);
		subs[2]=new FullSubscription();
		subs[2].setCustomer_id("203247267");
		subs[2].setCar_number("6666666");
		dates[2]=new Date();
		dates[2].setTime(dates[2].getTime()-1000*60*60*72);
		subs[2].setStart_date(dates[2]);
		dates[2]=(Date) dates[2].clone();
		dates[2].setTime(dates[2].getTime()+1000*60*60*96);
		subs[2].setEnd_date(dates[2]);
		return subs;
	}
	public static CasualSubscription [] getCasualSubscriptionById(String loggedIn) //can use "getCasualSubscriptions()"
	{
		CasualSubscription [] subs=new CasualSubscription[3];
		Date [] dates=new Date[3];
		
		
		
		subs[0]=new CasualSubscription();
		subs[0].setCustomer_id("203247267");
		subs[0].setCar_number("1111111");
		dates[0]=new Date();
		subs[0].setEnd_date(dates[0]);
		dates[0]=(Date) dates[0].clone();
		dates[0].setTime(dates[0].getTime()-1000*60*60*96);
		subs[0].setStart_date(dates[0]);
		subs[0].setleaving_time(11,0,0);
		subs[0].setParking_lot_number(1);
		subs[1]=new CasualSubscription();
		subs[1].setCustomer_id("203247267");
		subs[1].setCar_number("2222222");
		dates[1]=new Date();
		subs[1].setEnd_date(dates[1]);
		dates[1]=(Date) dates[1].clone();
		dates[1].setTime(dates[1].getTime()-1000*60*60*120);
		subs[1].setStart_date(dates[1]);
		subs[1].setleaving_time(12,0,0);
		subs[1].setParking_lot_number(2);
		subs[2]=new CasualSubscription();
		subs[2].setCustomer_id("203247267");
		subs[2].setCar_number("3333333");
		dates[2]=new Date();
		subs[2].setEnd_date(dates[2]);
		dates[2]=(Date) dates[2].clone();
		dates[2].setTime(dates[2].getTime()-1000*60*60*144);
		subs[2].setStart_date(dates[2]);
		subs[2].setleaving_time(1,0,0);
		subs[2].setParking_lot_number(3);
		return subs;
	}
	public static void UpdateOrderInDB(Object order) {	//ca use "getOrders()"
		System.out.println("updating parking lot: "+((Order)order).getOrderID());
		
	}

	public static Prices getCurrentPrices(int parkingLot) {		//get the current used prices record of the parking lot (the prices record with the latest date)
		return new Prices(parkingLot);
	}
	public static void saveOneTimeCostumerToDB(OneTimeCostumerOrder order) {
		System.out.println("saving one time costumer order: "+order);
		
	}
	public static ParkingLotWorker getPlWorkerByID(String id) {
		if(id=="203247267")
			return new ParkingLotWorker("203247267","or","marx","or@walla.com","1234",1);
		return null;
	}
	public static void saveDisabledPlaceToDB(DisabledPlace dp) {
		System.out.println("Disabled spot saved");
	}
	public static DisabledPlace getCurrentDisabledParkingSpot(int[] place,int parkingLot) {	//return the disabledPlace record with the input details THAT DOESNT HAVE END DATE
		DisabledPlace dp=new DisabledPlace(1,place,"sup");									//if there is no such record return null
		dp.setEnd(new Date());
		dp.setStart(new Date());
		return dp;
	}
	
	public static void updateDisabledSpot(DisabledPlace dp) {
		
	}
	public static Customer[] getCustomers(){
		Customer c=new Customer("203247267","or","marx","or@walla.com","1234");
		Customer cc[]=new Customer[1];
		cc[0]=c;
		return cc;
		}
	public static void updateCustomer(Customer c) {		//can use "getCostumers()"
		System.out.println(c.getCostumer_id()+" new balance: "+c.getAcc_balance()+"$");
	}

	
	public static void updateFullSubscription(FullSubscription fullSubscription) {	//can use "getFullSubscriptions()"
System.out.println("updating  "+fullSubscription);		
	}
	public static void updateCasualSubscription(
			CasualSubscription casualSubscription) {
		System.out.println("updating  "+casualSubscription);			
	}
	public static FullSubscription[] getFullSubscriptions() {
		return getFullSubscriptionById("203247267");
	}
	public static CasualSubscription[] getCasualSubscriptions() {
		return getCasualSubscriptionById("203247267");
	}
	public static OneTimeCostumerOrder[] getOneTimeCustomerOrders() {
		OneTimeCostumerOrder otco[]=new OneTimeCostumerOrder[3];
		Date d[]=new Date[3];
		d[0]=new Date();
		d[1]=new Date();
		d[2]=new Date();
		d[0].setTime(d[0].getTime()+1000*60*60*7);
		d[1].setTime(d[1].getTime()+1000*60*60*8);
		d[2].setTime(d[2].getTime()+1000*60*60*9);
		otco[0]=new OneTimeCostumerOrder("203247267", d[0], "or@walla.com", "1234568");
		otco[1]=new OneTimeCostumerOrder("111222333", d[1], "or1@walla.com", "1234569");
		otco[2]=new OneTimeCostumerOrder("333222111", d[2], "or2@walla.com", "1234560");
		Date d1=new Date();
		d1.setTime(d1.getTime()-1000*60*60*10);
		otco[0].setEntering_hour(d1);
		return otco;
	}
	public static void updateOneTimeCustomerOrder(
			OneTimeCostumerOrder oneTimeCostumerOrder) {
		// TODO Auto-generated method stub
		
	}
	public static void saveOrderToDB(Order order) {
		System.out.println("saving" +order.getCarNumber() + "  " + order.getArrivalDate());
		
	}
	
	

}
